//
//  WDWorderOrdMainVehDetailFlowView.m
//  wd-serviceapp
//
//  Created by Bin Tang on 2024/9/6.
//

#import "WDWorderOrdMainVehDetailFlowView.h"
#import "WDTaskFlowModel.h"
#import "WDWorderOrdMainVehSingleImageView.h"
#import "WDWorderOrdMainVehOtherImageVideoView.h" // 其它
#import "WDWorderOrdVehDetailReplacePartView.h" // 更换配件图片
#import "WDWorderOrdMainVehOtherImageVideoView.h" // 其它图片

@interface WDWorderOrdMainVehDetailFlowView ()

@property (nonatomic, strong) WDTaskFlowModel *model;

/// 处理后车辆状况
@property (nonatomic, strong) WDTaskDetailBasicSingleView *processedCondView;

/// 处理方式
@property (nonatomic, strong) WDTaskDetailBasicSingleView *processedModeView;

/// 处理说明
@property (nonatomic, strong) WDTaskDetailBasicSingleView *processedSpecView;

/// 更换配件图片
@property (nonatomic, strong) WDWorderOrdVehDetailReplacePartView *replacePartView;

/// 其他图片
@property (nonatomic, strong) WDWorderOrdMainVehOtherImageVideoView *otherImgVideoView;

/// 完成图片
@property (nonatomic, strong) WDWorderOrdMainVehOtherImageVideoView *finishImgVideoView;



/// 处理时间
@property (nonatomic, strong) WDTaskDetailBasicSingleView *processTimeView;

/// 处理账号
@property (nonatomic, strong) WDTaskDetailBasicSingleView *processAccountView;



/// 处理后车辆状况
- (void)initWithProcessedCondView;

/// 处理方式
- (void)initWithProcessedModeView;

/// 处理说明
- (void)initWithProcessedSpecView;

@end

@implementation WDWorderOrdMainVehDetailFlowView

- (void)initWithSubView {
    [super initWithSubView];
    
    self.backgroundColor = [UIColor whiteColor];
    
    CGRect frame = CGRectMake(20, 0, self.width - 40, 1);
    [CALayer drawLine:self frame:frame lineColor:[UIColor colorWithHexString:@"#DDDDDD"]];
}

/// 处理后车辆状况
- (void)initWithProcessedCondView {
    if (!_processedCondView) {
        CGRect frame = CGRectMake(0, 0, self.width, kWDTaskDetailBasicSingleViewHeight);
        _processedCondView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_processedCondView];
    }
    if (self.model) {
//        4.继续维修 5.完成维修
        NSString *str = @"";
        if (self.model.servOperate == 4) {
            str = @"继续维修";
        } else if (self.model.servOperate == 5) {
            str = @"完成维修";
        }
        [_processedCondView updateWithViewTitle:@"处理后车辆状况" value:str valueHeight:18];
    }
}

/// 处理方式
- (void)initWithProcessedModeView {
    if (!_processedModeView) {
        CGRect frame = self.processedCondView.frame;
        frame.origin.y = self.processedCondView.bottom;
        _processedModeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_processedModeView];
    }
    if (self.model) {
        [_processedModeView updateWithViewTitle:@"本次处理方式" value:self.model.workResult valueHeight:18];
    }
}

/// 处理说明
- (void)initWithProcessedSpecView {
    if (!_processedSpecView) {
        CGRect frame = self.processedCondView.frame;
        frame.origin.y = self.processedModeView.bottom;
        _processedSpecView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_processedSpecView];
    }
    if (self.model) {
        self.processedSpecView.height = 10 + self.model.workExplainHeight;
        [_processedSpecView updateWithViewTitle:@"本次处理说明" value:self.model.workExplain valueHeight:self.model.workExplainHeight];
    }
}

/// 更换配件图片
- (void)initWithReplacePartView {
    if (!_replacePartView) {
        CGRect frame = CGRectMake(0, self.processedSpecView.bottom, self.width, 0);
        _replacePartView = [[WDWorderOrdVehDetailReplacePartView alloc] initWithFrame:frame];
        [self addSubview:_replacePartView];
    }
    self.replacePartView.hidden = YES;
    if (self.model.files.count > 0) {
        self.replacePartView.hidden = NO;
        self.replacePartView.height = self.model.filesHeight;
        [self.replacePartView updateWithViewData:self.model.files];
    }
}

/// 其它图片
- (void)initWithOtherImgVideoView {
    if (!_otherImgVideoView) {
        CGRect frame = CGRectMake(0, self.replacePartView.bottom, self.width, 0);
        _otherImgVideoView = [[WDWorderOrdMainVehOtherImageVideoView alloc] initWithFrame:frame];
        [self addSubview:_otherImgVideoView];
    }
    self.otherImgVideoView.hidden = YES;
    if (self.model.otherFiles.count > 0) {
        self.otherImgVideoView.hidden = NO;
        if (self.replacePartView && self.replacePartView.hidden == NO) {
            self.otherImgVideoView.top = self.replacePartView.bottom + 18;
        } else {
            self.otherImgVideoView.top = self.processedSpecView.bottom + 12;
        }
        self.otherImgVideoView.height = self.model.otherFilesHeight;
        [self.otherImgVideoView updateWithViewTitle:@"其他照片/视频" images:self.model.otherFiles playVideoBlock:^(WDInspectUploadModel * _Nonnull model) {
            
        }];
    }
}

- (void)initWithFinishImgVideoView {
    if (!_finishImgVideoView) {
        CGRect frame = CGRectMake(0, self.replacePartView.bottom, self.width, 0);
        _finishImgVideoView = [[WDWorderOrdMainVehOtherImageVideoView alloc] initWithFrame:frame];
//        _finishImgVideoView.backgroundColor = [UIColor orangeColor];
        [self addSubview:_finishImgVideoView];
    }
    self.finishImgVideoView.hidden = YES;
    if (self.model.finishFiles.count > 0) {
        self.finishImgVideoView.hidden = NO;
        NSString *title = @"备注图片";
        BOOL ret1 = NO;
        BOOL ret2 = NO;
        float y = self.processedSpecView.bottom + 12;
        if (self.model.files.count > 0) {
            y = self.replacePartView.bottom + 12;
            title = @"备注图片";
            ret1 = YES;
        }
        if (self.model.otherFiles.count > 0) {
            y = self.otherImgVideoView.bottom + 12;
            title = @"备注图片";
            ret2 = YES;
        }
        if (ret1 && ret2) {
            title = @"备注图片";
        }
        self.finishImgVideoView.top = y;
        self.finishImgVideoView.height = self.model.finishFilesHeight;
        [self.finishImgVideoView updateWithViewTitle:title images:self.model.finishFiles playVideoBlock:^(WDInspectUploadModel * _Nonnull model) {
            
        }];
    }
}

/// 处理时间
- (void)initWithProcessTimeView {
    if (!_processTimeView) {
        CGRect frame = self.processedCondView.frame;
//        frame.origin.y = self.otherImageVideoView.bottom;
        _processTimeView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_processTimeView];
    }
    if (self.model) {
        float y = _processedSpecView.bottom;
        
        if (self.model.files.count > 0) {
            y = self.replacePartView.bottom;
        }
        if (self.model.otherFiles.count > 0) {
            y = self.otherImgVideoView.bottom;
        }
        if (self.model.finishFiles.count > 0) {
            y = self.finishImgVideoView.bottom;
        }
        self.processTimeView.top = y;
        [_processTimeView updateWithViewTitle:@"处理时间" value:self.model.createTime valueHeight:18];
    }
}

/// 处理账号
- (void)initWithProcessAccountView {
    if (!_processAccountView) {
        CGRect frame = self.processedCondView.frame;
        frame.origin.y = self.processTimeView.bottom;
        _processAccountView = [[WDTaskDetailBasicSingleView alloc] initWithFrame:frame];
        [self addSubview:_processAccountView];
    }
    if (self.model) {
        _processAccountView.top = self.processTimeView.bottom;
        [_processAccountView updateWithViewTitle:@"处理账号" value:self.model.engineerName valueHeight:18];
    }
}

- (void)updateWithViewData:(id)data {
    self.model = data;
    
    /// 处理后车辆状况
    [self initWithProcessedCondView];

    /// 处理方式
    [self initWithProcessedModeView];

    /// 处理说明
    [self initWithProcessedSpecView];

    /// 更换配件图片
    [self initWithReplacePartView];
    
    /// 其它图片
    [self initWithOtherImgVideoView];
    
    // 完成
    [self initWithFinishImgVideoView];
    
    /// 处理时间
    [self initWithProcessTimeView];

    /// 处理账号
    [self initWithProcessAccountView];
}

@end
